package cn.ailearn.exception.handler;

import cn.ailearn.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @ClassName GlobalExceptionHandler
 * @Description 全局异常处理器
 * @Author WDEMO
 * @Date 2025/10/22 17:26
 */

@Slf4j
//@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理认证相关异常
     */
    @ExceptionHandler({BadCredentialsException.class, AuthenticationException.class})
    public Result<String> handleAuthenticationException(Exception e) {
        log.error("认证异常: {}", e.getMessage());
        return Result.error("认证失败，请重新登录");
    }
}
